package com.export.xlsx.park;

import com.csvreader.CsvReader;
import com.export.xlsx.domain.Company;
import com.export.xlsx.service.BusinessService;
import com.export.xlsx.service.impl.BusinessServiceImpl;
import com.export.xlsx.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.nio.charset.Charset;

/**
 * 漕河泾园区（未入库）
 *
 * 2. 20171221-漕河泾园张江申报项目-数据采集表.csv
 *
 * Created by zhangls on 2018/1/12 0012.
 */
@Slf4j
public class ChjData1 {

    BusinessService businessService = new BusinessServiceImpl();

    @Test
    public void testDate1() throws Exception {
        CsvReader r = new CsvReader("D://20171221-漕河泾园张江申报项目-数据采集表.csv", ',', Charset.forName("UTF-8"));
        System.out.println(r.readHeaders());
        System.out.println(r.readHeaders());
        // 逐条读取记录，直至读完

        String parkId = "1001";

        while (r.readRecord()) {


            //基本信息
            String name = StringUtils.getStr(r.get(0));

            String addr = StringUtils.getStr(r.get(1));//经营地址
            String person = StringUtils.getStr(r.get(2));//法人
            String phone = StringUtils.getStr(r.get(3));//联系电话
            String email = StringUtils.getStr(r.get(4));//email
            String empSum = StringUtils.getStr(r.get(5));//职工总数
            String techSum = StringUtils.getStr(r.get(6));//技术员工

            String managerSum = StringUtils.getStr(r.get(7));//管理员工


            //第一步：查询现有表是否存在改记录
            Company company = new Company();
            company.setC1(name);
            company.setC2(parkId);

            if(null != businessService.findCompanyInfo(company)){
                //更新操作
                businessService.updateInfo1(company,phone,person,email,addr,empSum,techSum,managerSum);
            } else {
                // 新增操作
                businessService.insertInfo2(company,phone,person,email,addr,empSum,techSum,managerSum);
            }

            String benke = StringUtils.getStr(r.get(8));
            businessService.updateBenke(company,benke,1011, 2017);//本科
            String daz = StringUtils.getStr(r.get(9));
            businessService.updateBenke(company,daz,1012, 2017);//大专

            String xssr = StringUtils.getStr(r.get(10));//销售收入
            String jlr = StringUtils.getStr(r.get(11));//净利润
            String sjss = StringUtils.getStr(r.get(12));//实缴税收
            String chze = StringUtils.getStr(r.get(13));//创汇总额
            String zzc = StringUtils.getStr(r.get(14));//总资产
            String zfz = StringUtils.getStr(r.get(15));//总负债


            //学历信息
            businessService.insertInfo1(company,StringUtils.getStr(r.get(6)),1009, 2017);//博士
            businessService.insertInfo1(company,StringUtils.getStr(r.get(7)),1010, 2017);//硕士
            businessService.insertInfo1(company,StringUtils.getStr(r.get(8)),1011, 2017);//本科
            businessService.insertInfo1(company,StringUtils.getStr(r.get(9)),1012, 2017);//大专

            //营业收入
            String yysr2016 = StringUtils.getStr(r.get(11));
            businessService.insertInfo1(company, yysr2016,1000,2016);
            String yysr2015 = StringUtils.getStr(r.get(12));
            businessService.insertInfo1(company, yysr2015,1000,2015);
            String yysr2014 = StringUtils.getStr(r.get(13));
            businessService.insertInfo1(company, yysr2014,1000, 2014);

            //主营收入
            String zysr2016 = StringUtils.getStr(r.get(14));
            businessService.insertInfo1(company, zysr2016,1001, 2016);
            String zysr2015 = StringUtils.getStr(r.get(15));
            businessService.insertInfo1(company, zysr2015,1001, 2015);
            String zysr2014 = StringUtils.getStr(r.get(16));
            businessService.insertInfo1(company, zysr2014,1001, 2014);

            //高新技术产品（服务）收入（万元）
            String gxsr2016 = StringUtils.getStr(r.get(17));
            businessService.insertInfo1(company, gxsr2016,1002, 2016);
            String gxsr2015 = StringUtils.getStr(r.get(18));
            businessService.insertInfo1(company, gxsr2015,1002, 2015);
            String gxsr2014 = StringUtils.getStr(r.get(19));
            businessService.insertInfo1(company, gxsr2014,1002, 2014);

            // 净利润（万元）
            String lrsr2016 = StringUtils.getStr(r.get(20));
            businessService.insertInfo1(company, lrsr2016,1003, 2016);
            String lrsr2015 = StringUtils.getStr(r.get(21));
            businessService.insertInfo1(company, lrsr2015,1003, 2015);
            String lrsr2014 = StringUtils.getStr(r.get(22));
            businessService.insertInfo1(company, lrsr2014,1003, 2014);

            // 应交税费总额（万元）
            String jssr2016 = StringUtils.getStr(r.get(23));
            businessService.insertInfo1(company, jssr2016,1004, 2016);
            String jssr2015 = StringUtils.getStr(r.get(24));
            businessService.insertInfo1(company, jssr2015,1004, 2015);
            String jssr2014 = StringUtils.getStr(r.get(25));
            businessService.insertInfo1(company, jssr2014,1004, 2014);
            // 总资产（万元）
            String zcsr2016 = StringUtils.getStr(r.get(26));
            businessService.insertInfo1(company, zcsr2016,1005, 2016);
            String zcsr2015 = StringUtils.getStr(r.get(27));
            businessService.insertInfo1(company, zcsr2015,1005, 2015);
            String zcsr2014 = StringUtils.getStr(r.get(28));
            businessService.insertInfo1(company, zcsr2014,1005, 2014);
            // 负债总额（万元）
            String fzsr2016 = StringUtils.getStr(r.get(29));
            businessService.insertInfo1(company, fzsr2016,1006, 2016);
            String fzsr2015 = StringUtils.getStr(r.get(30));
            businessService.insertInfo1(company, fzsr2015,1006, 2015);
            String fzsr2014 = StringUtils.getStr(r.get(31));
            businessService.insertInfo1(company, fzsr2014,1006, 2014);
            // 固定资产总额（万元）
            String gdsr2016 = StringUtils.getStr(r.get(32));
            businessService.insertInfo1(company, gdsr2016,1007, 2016);
            String gdsr2015 = StringUtils.getStr(r.get(33));
            businessService.insertInfo1(company, gdsr2015,1007, 2015);
            String gdsr2014 = StringUtils.getStr(r.get(34));
            businessService.insertInfo1(company, gdsr2014,1007, 2014);
            // 科研投入总额（万元）
            String kysr2016 = StringUtils.getStr(r.get(35));
            businessService.insertInfo1(company, kysr2016,1008, 2016);
            String kysr2015 = StringUtils.getStr(r.get(36));
            businessService.insertInfo1(company, kysr2015,1008, 2015);
            String kysr2014 = StringUtils.getStr(r.get(37));
            businessService.insertInfo1(company, kysr2014,1008, 2014);
        }

        r.close();
    }
}
